﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class SparePartApplyConfirmRetrunProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialPage();
            }
        }

        private void InitialPage()
        {
            SparePartApplyService service = new SparePartApplyService();
            SparePartApplyForm sparePartApplyForm = service.GetProductDetailForm(long.Parse(Request.QueryString[Constants.QUERYSTR_SPAREPARTAPPLY_ID]));
            serviceStationLabel.Text = sparePartApplyForm.ServiceStation.Name;
            productTypeLabel.Text = sparePartApplyForm.ApplicationProduct.ProductType.ProductTypeName;
            sendDateLabel.Text = sparePartApplyForm.SendTime.HasValue ? sparePartApplyForm.SendTime.Value.ToString("yyyy-MM-dd") : "";

            returnProductTypeTextBox.Text = sparePartApplyForm.ApplicationProduct.ProductType.ProductTypeName;
            returnPrductSerialNumberTextBox.Text = sparePartApplyForm.ApplicationProduct.ProductSerialNumber;

            rmaCodeLabel.Text = sparePartApplyForm.ApplicationProduct.ApplicationForm.ApplicationCode;
            statusLabel.Text = sparePartApplyForm.Status;
        }


        protected void saveLinkButton_Click(object sender, EventArgs e)
        {
            try
            {
                SparePartApplyService service = new SparePartApplyService();
                SparePartApplyForm form = service.GetSparePartApplyFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_SPAREPARTAPPLY_ID]));

                form.Status = "备件-待归还确认";
                form.ReturnProductType = returnProductTypeTextBox.Text;
                form.ReturnProductSerialNumber = returnPrductSerialNumberTextBox.Text;
                form.SendReturnTime = DateTime.Now;

                service.Update(form);

                Response.Write(string.Format("<script language='JavaScript'> alert( '归还成功！');location.href= 'SparePartApplyListNeedReturn.aspx' </script>"));
            }
            catch (Exception ex)
            {
                LogUtility.LogUtilityIntance.LogException(ex, "SparePartApplyConfirmRetrunProduct.aspx::saveLinkButton_Click");
                throw ex;
            }
        }
    }
}
